Author: Nicolas Legrand nicolas.legrand@cfin.au.dk
import os
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
import numpy as np
import plotly.graph_objects as go
import plotly.express as px
from plotly.subplots import make_subplots
from systole.detection import oxi_peaks
from systole.plotly import plot_subspaces, plot_raw
import plotly.io as pio
pio.renderers.default='notebook'
sns.set_context('talk')
Import data
path = 'C:/Users/au646069/ECG/1_VPN_aux/'
subject = 'sub_0019'
# Parameters
subject = "sub_0020"
path = "C:/Users/au646069/ECG/1_VPN_aux/"
resultsFiles = os.listdir(os.path.join(path, subject, 'HBC'))
# Logs dataframe
df = pd.read_csv(os.path.join(path, subject, 'HBC', [file for file in resultsFiles if file.endswith('final.txt')][0]))
df
| nTrial | Reported | Condition | Duration | Confidence | ConfidenceRT | |
|---|---|---|---|---|---|---|
| 0 | 0 | 29 | Count | 45 | 3 | 8.616 |
| 1 | 1 | 26 | Count | 40 | 4 | 3.026 |
| 2 | 2 | 17 | Count | 30 | 3 | 4.714 |
| 3 | 3 | 16 | Count | 25 | 5 | 6.358 |
| 4 | 4 | 32 | Count | 50 | 2 | 1.625 |
| 5 | 5 | 36 | Count | 35 | 5 | 4.897 |
# PPG signal
ppg = {}
for i in range(6):
ppg[str(i)] = np.load(os.path.join(path, subject, 'HBC', f'{subject[4:]}_{i}.npy'))
signal, peaks = oxi_peaks(ppg['0'][0])
rr = np.diff(np.where(peaks)[0])
plot_subspaces(rr=rr, height=500)
plot_raw(signal, sfreq=1000)
print(f'Reported: {df.Reported.loc[0]} ; Detected : {np.sum(peaks)}')
Reported: 29 ; Detected : 59
signal, peaks = oxi_peaks(ppg['1'][0])
rr = np.diff(np.where(peaks)[0])
plot_subspaces(rr=rr, height=500)
plot_raw(signal, sfreq=1000)
print(f'Reported: {df.Reported.loc[1]} ; Detected : {np.sum(peaks)}')
Reported: 26 ; Detected : 55
signal, peaks = oxi_peaks(ppg['2'][0])
rr = np.diff(np.where(peaks)[0])
plot_subspaces(rr=rr, height=500)
plot_raw(signal, sfreq=1000)
print(f'Reported: {df.Reported.loc[2]} ; Detected : {np.sum(peaks)}')
Reported: 17 ; Detected : 43
signal, peaks = oxi_peaks(ppg['3'][0])
rr = np.diff(np.where(peaks)[0])
plot_subspaces(rr=rr, height=500)
plot_raw(signal, sfreq=1000)
print(f'Reported: {df.Reported.loc[3]} ; Detected : {np.sum(peaks)}')
Reported: 16 ; Detected : 39
signal, peaks = oxi_peaks(ppg['4'][0])
rr = np.diff(np.where(peaks)[0])
plot_subspaces(rr=rr, height=500)
plot_raw(signal, sfreq=1000)
print(f'Reported: {df.Reported.loc[4]} ; Detected : {np.sum(peaks)}')
Reported: 32 ; Detected : 70
signal, peaks = oxi_peaks(ppg['5'][0])
rr = np.diff(np.where(peaks)[0])
plot_subspaces(rr=rr, height=500)
plot_raw(signal, sfreq=1000)
print(f'Reported: {df.Reported.loc[5]} ; Detected : {np.sum(peaks)}')
Reported: 36 ; Detected : 48